//引入模块
const express = require("express")
const app = express()
const path = require("path")
const cookieParser = require("cookie-parser")
const session = require("express-session")
const bodyParser = require("body-parser")
const axios = require('axios')

//配置后端接口路径
axios.defaults.baseURL = 'http://101.35.138.144:8080/image'
    // axios.defaults.baseURL = 'http://49.234.24.157:8080/image'
    // axios.defaults.withCredentials = true

//配置静态资源
app.use("/public", express.static(path.join(__dirname, "./public")))
    //配置模板引擎
app.set("views", path.join(__dirname, "./views"))
app.set('view engine', 'art')
app.engine("art", require("express-art-template"))
app.engine("html", require("express-art-template"))


//配置session 
app.use(cookieParser())
app.use(session({
    secret: "secret key", //配置加密字符串，可以是随机的
    cookie: { maxAge: 60 * 60 * 60 * 1000 * 1000 * 1000 * 1000 }, //设置cookie的过期时间
    resave: false, //强制保存，即session的值不修改是也保存
    saveUninitialized: true, //无论你是否使用session，他都默认给你一把钥匙
}))

//配置post请求解析体
app.use(express.urlencoded({ extended: false }))
app.use(express.json())
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());

//路由挂载
const login = require('./router/admin/login')
const router = require('./router/router')
const admin = require('./router/admin')
const users = require('./router/admin/users')
const adminRouter = require('./router/admin/admin')
const first = require('./router/admin/firstClass')
const adminRouters = require('./router/admin/admin')
const userlogin = require('./router/login')
const userRouter = require('./router/user')
const second = require('./router/admin/secondClass')
const album = require('./router/album')
const adminAlbum = require('./router/admin/album')
const albumc = require('./router/admin/checkAlbum')
const userSearch = require('./router/userSearch')
const collection = require('./router/collection')
const passage = require('./router/passage')
const report = require('./router/admin/report')
const classfy = require('./router/classfy')
const comment = require('./router/comment')
const sessionRouter=require('./router/session')
const error=require('./router/error')

//使用路由
app.use('/admin',require('./middle/addmin'))
app.use(login)
app.use(userlogin)
app.use(router)
app.use(admin)
app.use(users)
app.use(adminRouter)
app.use(first)
app.use(userRouter)
app.use(second)
app.use(album)
app.use(collection)
app.use(adminAlbum)
app.use(albumc)
app.use(userSearch)
app.use(report)
app.use(classfy)
app.use(comment)
app.use(passage)
app.use(sessionRouter)
//error为错误跳转页面一定要放在所有路由下面
app.use(error)


app.listen(8081, () => {
    console.log("server running on http://localhost:8081/picture/homePage")
})